﻿using System.Deployment.Application;
using System.Windows;

namespace ElBruno.ClickOnceDemo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindowLoaded;
        }

        public void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            DisplayCurrentPublishVersion();
            DisplayPublishData();
        }

        private void DisplayPublishData()
        {
            lblData.Text = @"Not Defined :D";
            if (!ApplicationDeployment.IsNetworkDeployed) return;
            var ad = ApplicationDeployment.CurrentDeployment;
            var data = string.Format(@"ActivationUri: {0}
CurrentVersion: {1}
DataDirectory: {2}
IsFirstRun: {3}
TimeOfLastUpdateCheck: {4}
UpdatedApplicationFullName: {5}
UpdatedVersion: {6}
UpdateLocation: {7}", ad.ActivationUri, ad.CurrentVersion, ad.DataDirectory, ad.IsFirstRun, ad.TimeOfLastUpdateCheck, ad.UpdatedApplicationFullName, ad.UpdatedVersion, ad.UpdateLocation);
            lblData.Text = data;
        }

        private void DisplayCurrentPublishVersion()
        {
            Title = "El Bruno - ClickOnce Demo [N/A]";
            if (!ApplicationDeployment.IsNetworkDeployed) return;
            var ad = ApplicationDeployment.CurrentDeployment;
            Title = string.Format(@"El Bruno - ClickOnce Demo [{0}]", ad.CurrentVersion);
        }
    }
}
